﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace Curling
{
    public class AnimationManager
    {
        public double From { get; set; }
        public double To { get; set; }
        public double Duration { get; set; }
        public double Value { get; set; }

        public bool IsFinish { get; set; }

        private double CurrentTime;

        public delegate void FinishEventHandler(object sender, EventArgs e);
        public event FinishEventHandler Finish;
        
        public AnimationManager()
        {
            IsFinish = true;
        }

        public void Start()
        {
            CurrentTime = 0.0;
            IsFinish = false;
        }

        public double Update(double dT)
        {
            CurrentTime += dT;

            if (CurrentTime >= Duration)
            {
                CurrentTime = Duration;
                IsFinish = true;

                if (Finish != null)
                    Finish(this, EventArgs.Empty);
            }

            Value = From + (To - From) * (CurrentTime / Duration);

            return Value;
        }
    }
}
